package com.example.week2;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.week2.adapter.MyAdapter;
import com.example.week2.entity.JavaBean;
import com.example.week2.mvp.view.LoginActivity;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ArrayList<JavaBean> list=new ArrayList<>();
    private RecyclerView rv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        rv = (RecyclerView) findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("page","1");
        OkGo.<String>post("http://172.81.227.127:8055/swagger-ui.html#/hornet-travels-controller").params(hashMap).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                Toast.makeText(MainActivity.this, "" + response.body(), Toast.LENGTH_SHORT).show();
                List<JavaBean> javaBeans = JSONArray.parseArray(response.body(), JavaBean.class);
                list.addAll(javaBeans);
            }
        });
        MyAdapter myAdapter = new MyAdapter(R.layout.item, list);
        rv.setAdapter(myAdapter);

    }
}
